<template>
  <div>
    <a-modal v-model:visible="pageData.visible" width="95%" style="top: 10px; height: 95%" title="代码预览" :destroyOnClose="true">
      <template #footer>
        <a-button @click="pageData.visible = false">关闭</a-button>
      </template>
      <a-tabs v-model:activeKey="pageData.activePanelKey" size="default" hide-add>
        <a-tab-pane v-for="(value, key) in pageData.preview.data" :tab="key.substring(key.lastIndexOf('/') + 1, key.indexOf('.vm'))" :key="key">
          <pre v-if="pageData.activePanelKey === key" v-highlightjs><code> {{highlightedCode(value, key)}} </code></pre>
        </a-tab-pane>
      </a-tabs>
    </a-modal>
  </div>
</template>

<script setup>
import { reactive, ref } from 'vue';
import BearJiaUtil from '@/utils/BearJiaUtil.js';
import { previewTable } from '@/api/tool/gen';
// import hljs from "highlight.js/lib/highlight"
// import "highlight.js/styles/github-gist.css"
// hljs.registerLanguage("java", require("highlight.js/lib/languages/java"))
// hljs.registerLanguage("xml", require("highlight.js/lib/languages/xml"))
// hljs.registerLanguage("html", require("highlight.js/lib/languages/xml"))
// hljs.registerLanguage("vue", require("highlight.js/lib/languages/xml"))
// hljs.registerLanguage("javascript", require("highlight.js/lib/languages/javascript"))
// hljs.registerLanguage("sql", require("highlight.js/lib/languages/sql"))
// 当前页面使用的数据
const pageData = reactive({
  visible: false,
  preview: [],
  activePanelKey: '',
});

pageData.activePanelKey = 'vm/java/domain.java.vm';

const genBasicInfoForm = reactive({ visible: false, data: {} });
// 重置genBasicInfoForm
const resetgenBasicInfoForm = () => {
  BearJiaUtil.resetFormFieldsToEmpty(genBasicInfoForm.data);
  // 值为数组时，特殊处理下
  // genBasicInfoForm.data.postIds = [];
  // genBasicInfoForm.data.roleIds = [];
};

// 打开修改窗口
const openPreviewModal = (record) => {
  pageData.visible = true;
  previewTable(record.tableId).then((response) => {
    // console.log('response.data=' + JSON.stringify(response.data));
    pageData.preview.data = response.data;
  });
};

// 高亮显示
const highlightedCode = (code, key) => {
  console.log('key=' + key);
  return code;
};

// 对外暴露出去
defineExpose({
  openPreviewModal,
});
</script>

<style lang="less"></style>
